package com.xoa.service.budget;

import com.xoa.dao.budget.BudgetProcessLogMapper;
import com.xoa.model.budget.BudgetProcessLog;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.edu.ConstantsInfo;
import com.xoa.util.edu.WrapperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by gaosubo on 2018/11/19.
 */
@Service
public class BudgetProcessLogService {

    @Autowired
    BudgetProcessLogMapper budgetProcessLogMapper;

    public BaseWrapper queryBudgetProcessLog(Integer runId){
        BaseWrapper baseWrapper = new BaseWrapper();
        if(runId == null) {
            WrapperUtil.setError(baseWrapper, ConstantsInfo.REQUEST_DATA_MSG, ConstantsInfo.REQUEST_ERROR_CODE);
            return baseWrapper;
        }
        List<BudgetProcessLog> logList = budgetProcessLogMapper.selLogByRunId(runId);
        for (BudgetProcessLog budgetProcessLog : logList){
            this.checkPrcs(budgetProcessLog.getFlowPrcs(),budgetProcessLog);
        }
        WrapperUtil.setSuccess(baseWrapper, ConstantsInfo.FIND_SUCCESS_MSG, ConstantsInfo.REQUEST_SUCCESS_CODE,logList);
        return baseWrapper;
    }


    private static void checkPrcs(Integer flowPrcs,BudgetProcessLog budgetProcessLog){
        switch (flowPrcs){
            case 1:
                budgetProcessLog.setPrcsName("当事人申请");
                break;
            case 2:
                budgetProcessLog.setPrcsName("部门主管");
                break;
            case 3:
                budgetProcessLog.setPrcsName("校级主管");
                break;
            case 4:
                budgetProcessLog.setPrcsName("会计审核支付");
                break;
            case 5:
                budgetProcessLog.setPrcsName("财务主管审批");
                break;
            case 6:
                budgetProcessLog.setPrcsName("校长审批");
                break;
            case 7:
                budgetProcessLog.setPrcsName("出纳接收并与发起人预约时间");
                break;
            case 8:
                budgetProcessLog.setPrcsName("项目申请人结束");
                break;
            case 9:
                budgetProcessLog.setPrcsName("固定财产登记");
                break;
            case 10:
                budgetProcessLog.setPrcsName("办公室上传会议纪要");
                break;
        }
    }
}
